﻿namespace SZSLSystem.Common
{
    using System;
    using System.Text;
    using System.Text.RegularExpressions;
    using System.Web;
    using System.Web.UI.WebControls;

    public class PageValidate
    {
        private static Regex RegCHZN = new Regex("[\u4e00-\u9fa5]");
        private static Regex RegDecimal = new Regex("^[0-9]+[.]?[0-9]+$");
        private static Regex RegDecimalSign = new Regex("^[+-]?[0-9]+[.]?[0-9]+$");
        private static Regex RegEmail = new Regex(@"^[\w-]+@[\w-]+\.(com|net|org|edu|mil|tv|biz|info)$");
        private static Regex RegNumber = new Regex("^[0-9]+$");
        private static Regex RegNumberSign = new Regex("^[+-]?[0-9]+$");

        public static string Decode(string str)
        {
            str = str.Replace("<br>", "\n");
            str = str.Replace("&gt;", ">");
            str = str.Replace("&lt;", "<");
            str = str.Replace("&nbsp;", " ");
            str = str.Replace("&quot;", "\"");
            return str;
        }

        public static string Encode(string str)
        {
            str = str.Replace("&", "&amp;");
            str = str.Replace("'", "''");
            str = str.Replace("\"", "&quot;");
            str = str.Replace(" ", "&nbsp;");
            str = str.Replace("<", "&lt;");
            str = str.Replace(">", "&gt;");
            str = str.Replace("\n", "<br>");
            return str;
        }


     
        public static bool IsDecimal(string inputData)
        {
            return RegDecimal.Match(inputData).Success;
        }

        public static bool IsDecimalSign(string inputData)
        {
            return RegDecimalSign.Match(inputData).Success;
        }

      
        /// <summary>
        /// 检察是否正确的Email格式
        /// </summary>
        /// <param name="str">要检查的字串</param>
        /// <returns>bool</returns>
        public static bool IsEmail(string str)
        {
            Regex reg = new Regex(@"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$");
            return reg.IsMatch(str);
        }

        /// <summary>
        /// 检察是否正确的日期格式
        /// </summary>
        /// <param name="str">要检查的字串</param>
        /// <returns>bool</returns>
        public static bool IsDateTime(string str)
        {
            return Regex.IsMatch(str, @"(\d{4})-(\d{1,2})-(\d{1,2})");
        }

        public static bool IsHasCHZN(string inputData)
        {
            return RegCHZN.Match(inputData).Success;
        }
      
        public static bool IsNumber(string inputData)
        {
            return RegNumber.Match(inputData).Success;
        }

        public static bool IsNumberSign(string inputData)
        {
            return RegNumberSign.Match(inputData).Success;
        }

        public static bool IsIdCardNo(string inputData)
        {
            return Regex.IsMatch(inputData, @"^\d{18}$|^\d{15}$");
        }

        public static bool IsPostCode(string inputData)
        {
            return Regex.IsMatch(inputData, @"^\d{6}");
          
        }

        public static bool IsPhone(string inputData)
        {
            return Regex.IsMatch(inputData, @"^\d{7,8}$|^\d{11,12}$");

        }

        public static bool IsMobile(string inputData)
        {
            return Regex.IsMatch(inputData, @"^\d{11}$");

        }
       

      
    }
}

